package cn.itcast.tool;

import cn.hutool.core.util.StrUtil;
import cn.itcast.domain.CustomerInfo;
import cn.itcast.domain.MobilePlan;
import cn.itcast.service.ICustomerInfoService;
import cn.itcast.service.IMobilePlanService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class MyTool {
    @Autowired
    private IMobilePlanService mobilePlanService;

    @Autowired
    private ICustomerInfoService customerInfoService;
    @Tool(description = "根据条件查询套餐信息")
    public List<MobilePlan> queryMobilePlan(@ToolParam(description = "套餐查询条件") PlanQuery query){
        if (query==null){
            return mobilePlanService.list();
        }
        //sql:select * from course where monthlyFee=? and dataQuota=? and callDuration=? and additionalServices=? and order by?
        QueryWrapper<MobilePlan> qw = new QueryWrapper<>();
        qw.eq(query.getMonthlyFee()!=null,"monthly_fee", query.getMonthlyFee());
//        qw.eq(StrUtil.isNotBlank(query.getDataQuota()),"data_quota", query.getDataQuota());
//        qw.eq(StrUtil.isNotBlank(query.getCallDuration()),"call_duration", query.getCallDuration());
//        qw.eq(StrUtil.isNotBlank(query.getAdditionalServices()),"additional_services", query.getAdditionalServices());
        return mobilePlanService.list(qw);
    }

    @Tool(description = "给客户办理套餐,办理好之后告诉客户办理成功")
    public void handleMobilePlan(@ToolParam(description = "客户姓名") String name ,
                                 @ToolParam(description = "客户联系方式") String contact,
                                 @ToolParam(description = "客户身份证号") String idNumber,
                                 @ToolParam(required = false,description = "客户备注") String remark){
        CustomerInfo customerInfo = CustomerInfo.builder()
                .name(name)
                .contact(contact)
                .idNumber(idNumber)
                .remark(remark)
                .createTime(LocalDateTime.now())
                .build();
        customerInfoService.save(customerInfo);
    }

}
